<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 5rem;
            height: 50px;
            background-color: lightcoral;
        }
    </style>
</head>
<body>
    <div>
        11111111111
    </div>
    <script>
        window.onload = function (){
            
            console.log("加载完毕");
        }
        window.onresize = function (){
            console.log(11111111111111);    //视口发生改变的时候触发
        }
        var divEle = document.querySelector("div");
        window.onresize = function () {
            var w = window.innerWidth ;     //获取当前视口的宽度
            var res = w / 10 ; 
            console.log(res);
            document.documentElement.style.fontSize = res + "px" ;//设置根元素的font-size值
        }
        function changeFont(a){
            var w = window.innerWidth ; 
            var res = w / a ; 
            document.documentElement.style.fontSize = `${res}px`
        }
    </script>
</body>
</html>